package com.mc.web.controller.fil;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mc.common.annotation.Log;
import com.mc.common.core.controller.BaseController;
import com.mc.common.core.domain.AjaxResult;
import com.mc.common.enums.BusinessType;
import com.mc.fil.domain.FilBase;
import com.mc.fil.service.IFilBaseService;
import com.mc.common.utils.poi.ExcelUtil;
import com.mc.common.core.page.TableDataInfo;

/**
 * 基地信息Controller
 *
 * @author mc
 * @date 2021-04-12
 */
@RestController
@RequestMapping("/fil/base")
public class FilBaseController extends BaseController
{
    @Autowired
    private IFilBaseService filBaseService;

    /**
     * 查询基地信息列表
     */
    @PreAuthorize("@ss.hasPermi('fil:base:list')")
    @GetMapping("/list")
    public TableDataInfo list(FilBase filBase)
    {
        startPage();
        List<FilBase> list = filBaseService.selectFilBaseList(filBase);
        return getDataTable(list);
    }

    /**
     * 导出基地信息列表
     */
    @PreAuthorize("@ss.hasPermi('fil:base:export')")
    @Log(title = "基地信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FilBase filBase)
    {
        List<FilBase> list = filBaseService.selectFilBaseList(filBase);
        ExcelUtil<FilBase> util = new ExcelUtil<FilBase>(FilBase.class);
        return util.exportExcel(list, "base");
    }

    /**
     * 获取基地信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('fil:base:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(filBaseService.selectFilBaseById(id));
    }

    /**
     * 新增基地信息
     */
    @PreAuthorize("@ss.hasPermi('fil:base:add')")
    @Log(title = "基地信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FilBase filBase)
    {
        return toAjax(filBaseService.insertFilBase(filBase));
    }

    /**
     * 修改基地信息
     */
    @PreAuthorize("@ss.hasPermi('fil:base:edit')")
    @Log(title = "基地信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FilBase filBase)
    {
        return toAjax(filBaseService.updateFilBase(filBase));
    }

    /**
     * 删除基地信息
     */
    @PreAuthorize("@ss.hasPermi('fil:base:remove')")
    @Log(title = "基地信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable String id)
    {
        return toAjax(filBaseService.deleteFilBaseById(id));
    }
}